/*
 *  Composer0005.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/09/05.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "Composer0005.h"
#include "../sc/Common/WellTemperament.h"

void Composer0005::Compose( std::string folderPath )
{	
	SubComposeOnWellTempered( folderPath );
	
	double tempo = 100.0;
	TimeController timeController( tempo, 4.5, 4 );
	double playingTime = timeController.GetSecondsToBarCount( 2 );
	double attackEndTime = 0.02;
	double decayEndTime = attackEndTime + 0.02;
	double sustainEndTime = decayEndTime + playingTime - 3 * 0.02;
	double releaseEndTime = sustainEndTime + 0.02;
	const Line* attackLine	=	& LineFactory::Create( Line::Type_Straight,	0.0,			0.0,	attackEndTime,		0.16 );
	const Line* decayLine	=	& LineFactory::Create( Line::Type_Straight,	attackEndTime,	0.16,	decayEndTime,		0.14 );
	const Line* sustainLine =	& LineFactory::Create( Line::Type_Straight,	decayEndTime,	0.14,	sustainEndTime,		0.14 );
	const Line* releaseLine =	& LineFactory::Create( Line::Type_Straight,	sustainEndTime,	0.14,	releaseEndTime,		0.0 );

	{
		double halfNoteSwell = timeController.GetNoteSwell( TimeController::HalfNote );
		double quaterNoteSwell = timeController.GetNoteSwell( TimeController::QuarterNote );
		double quaterNoteTripletSwell = timeController.GetNoteSwell( TimeController::QuarterNoteTriplet );

		double noteA_Hz = WellTemperament::GetFrequency( Note::A, 0 );
		double noteAPrime_Hz = noteA_Hz + halfNoteSwell;
		double noteG_Hz = WellTemperament::GetFrequency( Note::E, 2 );
		double noteGPrime_Hz = noteG_Hz + quaterNoteSwell;
		double noteC_Hz = WellTemperament::GetFrequency( Note::B, 2 );
		double noteCPrime_Hz = noteC_Hz + quaterNoteTripletSwell;
		
		const WaveTable& tableNoteA = WaveTableFactory::Create( WaveTable::Type_Sine, noteA_Hz );
		const WaveTable& tableNoteG = WaveTableFactory::Create( WaveTable::Type_Sine, noteG_Hz );
		const WaveTable& tableNoteC = WaveTableFactory::Create( WaveTable::Type_Sine, noteC_Hz );
		
		const SoundElement32* elementNoteA = 
			SoundElementFactory32::Create( attackEndTime, attackLine, decayEndTime, decayLine,
				sustainEndTime, sustainLine, releaseEndTime, releaseLine, tableNoteA );
		const SoundElement32* elementNoteAPrime =
			SoundElementFactory32::CreateWithFrequency( elementNoteA, noteAPrime_Hz );

		const SoundElement32* elementNoteG = 
			SoundElementFactory32::Create( attackEndTime, attackLine, decayEndTime, decayLine,
				sustainEndTime, sustainLine, releaseEndTime, releaseLine, tableNoteG );
		const SoundElement32* elementNoteGPrime =
			SoundElementFactory32::CreateWithFrequency( elementNoteG, noteGPrime_Hz );

		const SoundElement32* elementNoteC = 
			SoundElementFactory32::Create( attackEndTime, attackLine, decayEndTime, decayLine,
				sustainEndTime, sustainLine, releaseEndTime, releaseLine, tableNoteC );
		const SoundElement32* elementNoteCPrime =
			SoundElementFactory32::CreateWithFrequency( elementNoteC, noteCPrime_Hz );

		AudioRecorder32 recorder( 2, 1 );
		recorder.Record( 0, 0, 0, elementNoteA, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteAPrime, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteG, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteGPrime, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteC, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteCPrime, 0.5, 0.5 );
		recorder.OutputAudioFile( kAudioFileWAVEType, folderPath + "a.wav" );
	}

	{
//		double halfNoteSwell = timeController.GetNoteSwell( TimeController::HalfNote );
		double quaterNoteSwell = timeController.GetNoteSwell( TimeController::QuarterNote );
		double quaterNoteTripletSwell = timeController.GetNoteSwell( TimeController::QuarterNoteTriplet );
		double quintetNoteTriplet = 5 * timeController.GetNoteSwell( TimeController::QuarterNoteTriplet );

		double noteG_Hz = WellTemperament::GetFrequency( Note::G, 1 );
		double noteGPrime_Hz = noteG_Hz + quaterNoteSwell;
		double noteFSharp_Hz = WellTemperament::GetFrequency( Note::FSharp, 1 );
		double noteFSharpPrime_Hz = noteFSharp_Hz + quintetNoteTriplet;
		double noteB_Hz = WellTemperament::GetFrequency( Note::B, 1 );
		double noteBPrime_Hz = noteB_Hz + quaterNoteTripletSwell;
		
		const WaveTable& tableNoteG = WaveTableFactory::Create( WaveTable::Type_Sine, noteG_Hz );
		const WaveTable& tableNoteFSharp = WaveTableFactory::Create( WaveTable::Type_Sine, noteFSharp_Hz );
		const WaveTable& tableNoteB = WaveTableFactory::Create( WaveTable::Type_Sine, noteB_Hz );
		
		const SoundElement32* elementNoteG = 
			SoundElementFactory32::Create( attackEndTime, attackLine, decayEndTime, decayLine,
				sustainEndTime, sustainLine, releaseEndTime, releaseLine, tableNoteG );
		const SoundElement32* elementNoteGPrime =
			SoundElementFactory32::CreateWithFrequency( elementNoteG, noteGPrime_Hz );

		const SoundElement32* elementNoteFSharp = 
			SoundElementFactory32::Create( attackEndTime, attackLine, decayEndTime, decayLine,
				sustainEndTime, sustainLine, releaseEndTime, releaseLine, tableNoteFSharp );
		const SoundElement32* elementNoteFSharpPrime =
			SoundElementFactory32::CreateWithFrequency( elementNoteFSharp, noteFSharpPrime_Hz );

		const SoundElement32* elementNoteB = 
			SoundElementFactory32::Create( attackEndTime, attackLine, decayEndTime, decayLine,
				sustainEndTime, sustainLine, releaseEndTime, releaseLine, tableNoteB );
		const SoundElement32* elementNoteBPrime =
			SoundElementFactory32::CreateWithFrequency( elementNoteB, noteBPrime_Hz );

		AudioRecorder32 recorder( 2, 1 );
		recorder.Record( 0, 0, 0, elementNoteG, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteGPrime, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteFSharp, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteFSharpPrime, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteB, 0.5, 0.5 );
		recorder.Record( 0, 0, 0, elementNoteBPrime, 0.5, 0.5 );
		recorder.OutputAudioFile( kAudioFileWAVEType, folderPath + "b.wav" );
	}
	
	SubCompose( folderPath );

}


void Composer0005::SubCompose( std::string folderPath )
{
	const double swell = 2;
	const double octave = 2;
	const double maxDynamics = 0.4;
	const double length0 = 8;
	const double length = 12;

	const double noteC_Hz = WellTemperament::GetFrequency( Note::C, octave );
	const double noteCPrime_Hz = WellTemperament::GetFrequency( Note::C, octave ) + swell;
	const double noteCPrime2_Hz = WellTemperament::GetFrequency( Note::C, octave ) + ( 1. / 3. ) * swell;
	const double noteCPrime3_Hz = WellTemperament::GetFrequency( Note::C, octave ) + ( 1. / 9. ) * swell;

	const double noteG_Hz = WellTemperament::GetFrequency( Note::G, octave );
	const double noteGPrime_Hz = WellTemperament::GetFrequency( Note::G, octave ) + swell;
	const double noteGPrime2_Hz = WellTemperament::GetFrequency( Note::G, octave ) + 3 * swell;
	const double noteGPrime3_Hz = WellTemperament::GetFrequency( Note::G, octave ) + ( 1. / 3. ) * swell;

	const double noteD_Hz = WellTemperament::GetFrequency( Note::D, octave );	
	const double noteDPrime_Hz = WellTemperament::GetFrequency( Note::D, octave ) + swell;
	const double noteDPrime2_Hz = WellTemperament::GetFrequency( Note::D, octave ) + 3 * swell;
	const double noteDPrime3_Hz = WellTemperament::GetFrequency( Note::D, octave ) + 9 * swell;

	const SoundElement32* elementC_0 = SoundGenerator::Generate( noteC_Hz, length0, maxDynamics ); 
	const SoundElement32* elementCPrime_0 = SoundGenerator::Generate( noteCPrime_Hz, length0, maxDynamics ); 
	const SoundElement32* elementCPrime2_0 = SoundGenerator::Generate( noteCPrime2_Hz, length0, maxDynamics ); 
	const SoundElement32* elementCPrime3_0 = SoundGenerator::Generate( noteCPrime3_Hz, length0, maxDynamics ); 

//	const SoundElement32* elementC = SoundGenerator::Generate( noteC_Hz, length, maxDynamics ); 
//	const SoundElement32* elementCPrime = SoundGenerator::Generate( noteCPrime_Hz, length, maxDynamics ); 
//	const SoundElement32* elementCPrime2 = SoundGenerator::Generate( noteCPrime2_Hz, length, maxDynamics ); 
//	const SoundElement32* elementCPrime3 = SoundGenerator::Generate( noteCPrime3_Hz, length, maxDynamics ); 

	const SoundElement32* elementG = SoundGenerator::Generate( noteG_Hz, length, maxDynamics );
	const SoundElement32* elementGPrime = SoundGenerator::Generate( noteGPrime_Hz, length, maxDynamics ); 
	const SoundElement32* elementGPrime2 = SoundGenerator::Generate( noteGPrime2_Hz, length, maxDynamics ); 
	const SoundElement32* elementGPrime3 = SoundGenerator::Generate( noteGPrime3_Hz, length, maxDynamics ); 

	const SoundElement32* elementD = SoundGenerator::Generate( noteD_Hz, length, maxDynamics );
	const SoundElement32* elementDPrime = SoundGenerator::Generate( noteDPrime_Hz, length, maxDynamics ); 
	const SoundElement32* elementDPrime2 = SoundGenerator::Generate( noteDPrime2_Hz, length, maxDynamics ); 
	const SoundElement32* elementDPrime3 = SoundGenerator::Generate( noteDPrime3_Hz, length, maxDynamics ); 

	double time = 0;
	AudioRecorder32 recorder( 2, 1 );
	recorder.Record( 0, 0, time, elementC_0, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementCPrime_0, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementCPrime2_0, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementCPrime3_0, 0.5, 0.5 );

	time += length0;
//	recorder.Record( 0, 0, time, elementC, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementCPrime, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementCPrime2, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementCPrime3, 0.5, 0.5 );

	recorder.Record( 0, 0, time, elementG, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementGPrime, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementGPrime2, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementGPrime3, 0.5, 0.5 );

	time += length;
//	recorder.Record( 0, 0, time, elementC, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementCPrime, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementCPrime2, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementCPrime3, 0.5, 0.5 );
//
//	recorder.Record( 0, 0, time, elementG, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementGPrime, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementGPrime2, 0.5, 0.5 );
//	recorder.Record( 0, 0, time, elementGPrime3, 0.5, 0.5 );

	recorder.Record( 0, 0, time, elementD, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementDPrime, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementDPrime2, 0.5, 0.5 );
	recorder.Record( 0, 0, time, elementDPrime3, 0.5, 0.5 );

	recorder.OutputAudioFile( kAudioFileWAVEType, folderPath + "sub.wav" );
 /*
	std::vector< float > data0;
	std::vector< float > data1;
	std::vector< std::vector< float >* > audioDataByChannel( 2 );
	audioDataByChannel[ 0 ] = & data0;
	audioDataByChannel[ 1 ] = & data1;
	recorder.GetAudioData( 0, data0 );
	recorder.GetAudioData( 1, data1 );

	AudioPlayer player;
	player.LoadAudioData( audioDataByChannel );
	player.Play( 0 );
	while ( player.IsPlaying() )
	{
		usleep( 1000 );
	}
	player.Stop();
*/
}

void Composer0005::SubComposeOnWellTempered( std::string folderPath )
{
/*
66 dotted 4th = 60 sec
1 dotted 4th = 60 / 66 sec
1 8th = 20 / 66 sec
1 bar = dotted 4th * 3 = 60 / 22 sec
*/
	const double swell = 40.0 / 66.0;
	const double maxDynamics = 0.3;
	const double length = 4;
//	const double length = 60.0 / 22.0;

	double time = 0;
	AudioRecorder32 recorder( 2, 1 );

	//	1st chord
	{
		const double noteHz_1st = WellTemperament::GetFrequency( Note::A, -2 );
		const double noteHz_2nd = WellTemperament::GetFrequency( Note::E, -1 );
		const double noteHz_3rd = WellTemperament::GetFrequency( Note::A, -1 );
		const double noteHz_4th = WellTemperament::GetFrequency( Note::A, 0 );
		const double noteHz_5th = WellTemperament::GetFrequency( Note::G, 1 );
		const double noteHz_6th = WellTemperament::GetFrequency( Note::C, 2 );

		const double noteHz_1st_ = WellTemperament::GetFrequency( Note::A, -2 ) + swell;
		const double noteHz_2nd_ = WellTemperament::GetFrequency( Note::E, -1 ) + ( 3.0 / 2.0 ) * swell;
		const double noteHz_3rd_ = WellTemperament::GetFrequency( Note::A, -1 ) + 2.0 * swell;
		const double noteHz_4th_ = WellTemperament::GetFrequency( Note::A, 0 ) + 4.0 * swell;
		const double noteHz_5th_ = WellTemperament::GetFrequency( Note::G, 1 ) + ( 64.0 / 9.0 ) * swell;
		const double noteHz_6th_ = WellTemperament::GetFrequency( Note::C, 2 ) + ( 48.0 / 5.0 ) * swell;

		const SoundElement32* element_1st = SoundGenerator::Generate( noteHz_1st, length, maxDynamics ); 
		const SoundElement32* element_2nd = SoundGenerator::Generate( noteHz_2nd, length, maxDynamics ); 
		const SoundElement32* element_3rd = SoundGenerator::Generate( noteHz_3rd, length, maxDynamics ); 
		const SoundElement32* element_4th = SoundGenerator::Generate( noteHz_4th, length, maxDynamics ); 
		const SoundElement32* element_5th = SoundGenerator::Generate( noteHz_5th, length, maxDynamics ); 
		const SoundElement32* element_6th = SoundGenerator::Generate( noteHz_6th, length, maxDynamics ); 

		const SoundElement32* element_1st_ = SoundGenerator::Generate( noteHz_1st_, length, maxDynamics ); 
		const SoundElement32* element_2nd_ = SoundGenerator::Generate( noteHz_2nd_, length, maxDynamics ); 
		const SoundElement32* element_3rd_ = SoundGenerator::Generate( noteHz_3rd_, length, maxDynamics ); 
		const SoundElement32* element_4th_ = SoundGenerator::Generate( noteHz_4th_, length, maxDynamics ); 
		const SoundElement32* element_5th_ = SoundGenerator::Generate( noteHz_5th_, length, maxDynamics ); 
		const SoundElement32* element_6th_ = SoundGenerator::Generate( noteHz_6th_, length, maxDynamics ); 

		recorder.Record( 0, 0, time, element_1st, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th, 0.5, 0.5 );

		recorder.Record( 0, 0, time, element_1st_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th_, 0.5, 0.5 );
	}
	
	//	2nd chord
	time += length;
	{
		const double noteHz_1st = WellTemperament::GetFrequency( Note::A, -2 );
		const double noteHz_2nd = WellTemperament::GetFrequency( Note::E, -1 );
		const double noteHz_3rd = WellTemperament::GetFrequency( Note::G, -1 );
		const double noteHz_4th = WellTemperament::GetFrequency( Note::G, 0 );
		const double noteHz_5th = WellTemperament::GetFrequency( Note::FSharp, 1 );
		const double noteHz_6th = WellTemperament::GetFrequency( Note::B, 1 );

		const double noteHz_1st_ = WellTemperament::GetFrequency( Note::A, -2 ) + swell;
		const double noteHz_2nd_ = WellTemperament::GetFrequency( Note::E, -1 ) + ( 3.0 / 2.0 ) * swell;
		const double noteHz_3rd_ = WellTemperament::GetFrequency( Note::G, -1 ) + ( 16.0 / 9.0 ) * swell;
		const double noteHz_4th_ = WellTemperament::GetFrequency( Note::G, 0 ) + ( 32 / 9.0 ) * swell;
		const double noteHz_5th_ = WellTemperament::GetFrequency( Note::FSharp, 1 ) + ( 20.0 / 6.0 ) * swell;
		const double noteHz_6th_ = WellTemperament::GetFrequency( Note::B, 1 ) + 9.0 * swell;

		const SoundElement32* element_1st = SoundGenerator::Generate( noteHz_1st, length, maxDynamics ); 
		const SoundElement32* element_2nd = SoundGenerator::Generate( noteHz_2nd, length, maxDynamics ); 
		const SoundElement32* element_3rd = SoundGenerator::Generate( noteHz_3rd, length, maxDynamics ); 
		const SoundElement32* element_4th = SoundGenerator::Generate( noteHz_4th, length, maxDynamics ); 
		const SoundElement32* element_5th = SoundGenerator::Generate( noteHz_5th, length, maxDynamics ); 
		const SoundElement32* element_6th = SoundGenerator::Generate( noteHz_6th, length, maxDynamics ); 

		const SoundElement32* element_1st_ = SoundGenerator::Generate( noteHz_1st_, length, maxDynamics ); 
		const SoundElement32* element_2nd_ = SoundGenerator::Generate( noteHz_2nd_, length, maxDynamics ); 
		const SoundElement32* element_3rd_ = SoundGenerator::Generate( noteHz_3rd_, length, maxDynamics ); 
		const SoundElement32* element_4th_ = SoundGenerator::Generate( noteHz_4th_, length, maxDynamics ); 
		const SoundElement32* element_5th_ = SoundGenerator::Generate( noteHz_5th_, length, maxDynamics ); 
		const SoundElement32* element_6th_ = SoundGenerator::Generate( noteHz_6th_, length, maxDynamics ); 

		recorder.Record( 0, 0, time, element_1st, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th, 0.5, 0.5 );

		recorder.Record( 0, 0, time, element_1st_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th_, 0.5, 0.5 );
	}
	
	time += length;
	//	3rd chord
	{
		const double noteHz_1st = WellTemperament::GetFrequency( Note::A, -2 );
		const double noteHz_2nd = WellTemperament::GetFrequency( Note::E, -1 );
		const double noteHz_3rd = WellTemperament::GetFrequency( Note::G, -1 );
		const double noteHz_4th = WellTemperament::GetFrequency( Note::G, 0 );
		const double noteHz_5th = WellTemperament::GetFrequency( Note::FSharp, 1 );
		const double noteHz_6th = WellTemperament::GetFrequency( Note::A, 1 );

		const double noteHz_1st_ = WellTemperament::GetFrequency( Note::A, -2 ) + swell;
		const double noteHz_2nd_ = WellTemperament::GetFrequency( Note::E, -1 ) + ( 3.0 / 2.0 ) * swell;
		const double noteHz_3rd_ = WellTemperament::GetFrequency( Note::G, -1 ) + ( 16.0 / 9.0 ) * swell;
		const double noteHz_4th_ = WellTemperament::GetFrequency( Note::G, 0 ) + ( 32 / 9.0 ) * swell;
		const double noteHz_5th_ = WellTemperament::GetFrequency( Note::FSharp, 1 ) + ( 20.0 / 6.0 ) * swell;
		const double noteHz_6th_ = WellTemperament::GetFrequency( Note::A, 1 ) + 8.0 * swell;

		const SoundElement32* element_1st = SoundGenerator::Generate( noteHz_1st, length, maxDynamics ); 
		const SoundElement32* element_2nd = SoundGenerator::Generate( noteHz_2nd, length, maxDynamics ); 
		const SoundElement32* element_3rd = SoundGenerator::Generate( noteHz_3rd, length, maxDynamics ); 
		const SoundElement32* element_4th = SoundGenerator::Generate( noteHz_4th, length, maxDynamics ); 
		const SoundElement32* element_5th = SoundGenerator::Generate( noteHz_5th, length, maxDynamics ); 
		const SoundElement32* element_6th = SoundGenerator::Generate( noteHz_6th, length, maxDynamics ); 

		const SoundElement32* element_1st_ = SoundGenerator::Generate( noteHz_1st_, length, maxDynamics ); 
		const SoundElement32* element_2nd_ = SoundGenerator::Generate( noteHz_2nd_, length, maxDynamics ); 
		const SoundElement32* element_3rd_ = SoundGenerator::Generate( noteHz_3rd_, length, maxDynamics ); 
		const SoundElement32* element_4th_ = SoundGenerator::Generate( noteHz_4th_, length, maxDynamics ); 
		const SoundElement32* element_5th_ = SoundGenerator::Generate( noteHz_5th_, length, maxDynamics ); 
		const SoundElement32* element_6th_ = SoundGenerator::Generate( noteHz_6th_, length, maxDynamics ); 

		recorder.Record( 0, 0, time, element_1st, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th, 0.5, 0.5 );

		recorder.Record( 0, 0, time, element_1st_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th_, 0.5, 0.5 );
	}

	time += length;
	//4th chord
	{
		const double noteHz_1st = WellTemperament::GetFrequency( Note::A, -2 );
		const double noteHz_2nd = WellTemperament::GetFrequency( Note::D, -1 );
		const double noteHz_3rd = WellTemperament::GetFrequency( Note::A, -1 );
		const double noteHz_4th = WellTemperament::GetFrequency( Note::C, 1 );
		const double noteHz_5th = WellTemperament::GetFrequency( Note::G, 1 );
		const double noteHz_6th = WellTemperament::GetFrequency( Note::B, 1 );

		const double noteHz_1st_ = WellTemperament::GetFrequency( Note::A, -2 ) + swell;
		const double noteHz_2nd_ = WellTemperament::GetFrequency( Note::D, -1 ) + ( 4.0 / 3.0 ) * swell;
		const double noteHz_3rd_ = WellTemperament::GetFrequency( Note::A, -1 ) + 2.0 * swell;
		const double noteHz_4th_ = WellTemperament::GetFrequency( Note::C, 1 ) + ( 24.0 / 5.0 ) * swell;
		const double noteHz_5th_ = WellTemperament::GetFrequency( Note::G, 1 ) + ( 64.0 / 9.0 ) * swell;
		const double noteHz_6th_ = WellTemperament::GetFrequency( Note::B, 1 ) + ( 32.0 / 3.0 ) * swell;

		const SoundElement32* element_1st = SoundGenerator::Generate( noteHz_1st, length, maxDynamics ); 
		const SoundElement32* element_2nd = SoundGenerator::Generate( noteHz_2nd, length, maxDynamics ); 
		const SoundElement32* element_3rd = SoundGenerator::Generate( noteHz_3rd, length, maxDynamics ); 
		const SoundElement32* element_4th = SoundGenerator::Generate( noteHz_4th, length, maxDynamics ); 
		const SoundElement32* element_5th = SoundGenerator::Generate( noteHz_5th, length, maxDynamics ); 
		const SoundElement32* element_6th = SoundGenerator::Generate( noteHz_6th, length, maxDynamics ); 

		const SoundElement32* element_1st_ = SoundGenerator::Generate( noteHz_1st_, length, maxDynamics ); 
		const SoundElement32* element_2nd_ = SoundGenerator::Generate( noteHz_2nd_, length, maxDynamics ); 
		const SoundElement32* element_3rd_ = SoundGenerator::Generate( noteHz_3rd_, length, maxDynamics ); 
		const SoundElement32* element_4th_ = SoundGenerator::Generate( noteHz_4th_, length, maxDynamics ); 
		const SoundElement32* element_5th_ = SoundGenerator::Generate( noteHz_5th_, length, maxDynamics ); 
		const SoundElement32* element_6th_ = SoundGenerator::Generate( noteHz_6th_, length, maxDynamics ); 

		recorder.Record( 0, 0, time, element_1st, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th, 0.5, 0.5 );

		recorder.Record( 0, 0, time, element_1st_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th_, 0.5, 0.5 );
	}

	time += length;
	//	5th chord
	{
		const double noteHz_1st = WellTemperament::GetFrequency( Note::A, -2 );
		const double noteHz_2nd = WellTemperament::GetFrequency( Note::E, -1 );
		const double noteHz_3rd = WellTemperament::GetFrequency( Note::A, -1 );
		const double noteHz_4th = WellTemperament::GetFrequency( Note::D, 1 );
		const double noteHz_5th = WellTemperament::GetFrequency( Note::G, 1 );
		const double noteHz_6th = WellTemperament::GetFrequency( Note::E, 2 );

		const double noteHz_1st_ = WellTemperament::GetFrequency( Note::A, -2 ) + swell;
		const double noteHz_2nd_ = WellTemperament::GetFrequency( Note::E, -1 ) + ( 3.0 / 2.0 ) * swell;
		const double noteHz_3rd_ = WellTemperament::GetFrequency( Note::A, -1 ) + 2.0 * swell;
		const double noteHz_4th_ = WellTemperament::GetFrequency( Note::D, 1 ) + ( 16.0 / 3.0 ) * swell;
		const double noteHz_5th_ = WellTemperament::GetFrequency( Note::G, 1 ) + ( 64.0 / 9.0 ) * swell;
		const double noteHz_6th_ = WellTemperament::GetFrequency( Note::E, 2 ) + 12.0 * swell;

		const SoundElement32* element_1st = SoundGenerator::Generate( noteHz_1st, length, maxDynamics ); 
		const SoundElement32* element_2nd = SoundGenerator::Generate( noteHz_2nd, length, maxDynamics ); 
		const SoundElement32* element_3rd = SoundGenerator::Generate( noteHz_3rd, length, maxDynamics ); 
		const SoundElement32* element_4th = SoundGenerator::Generate( noteHz_4th, length, maxDynamics ); 
		const SoundElement32* element_5th = SoundGenerator::Generate( noteHz_5th, length, maxDynamics ); 
		const SoundElement32* element_6th = SoundGenerator::Generate( noteHz_6th, length, maxDynamics ); 

		const SoundElement32* element_1st_ = SoundGenerator::Generate( noteHz_1st_, length, maxDynamics ); 
		const SoundElement32* element_2nd_ = SoundGenerator::Generate( noteHz_2nd_, length, maxDynamics ); 
		const SoundElement32* element_3rd_ = SoundGenerator::Generate( noteHz_3rd_, length, maxDynamics ); 
		const SoundElement32* element_4th_ = SoundGenerator::Generate( noteHz_4th_, length, maxDynamics ); 
		const SoundElement32* element_5th_ = SoundGenerator::Generate( noteHz_5th_, length, maxDynamics ); 
		const SoundElement32* element_6th_ = SoundGenerator::Generate( noteHz_6th_, length, maxDynamics ); 

		recorder.Record( 0, 0, time, element_1st, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th, 0.5, 0.5 );

		recorder.Record( 0, 0, time, element_1st_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th_, 0.5, 0.5 );
	}

	time += length;
	//	6th chord
	{
		const double noteHz_1st = WellTemperament::GetFrequency( Note::A, -2 );
		const double noteHz_2nd = WellTemperament::GetFrequency( Note::E, -1 );
		const double noteHz_3rd = WellTemperament::GetFrequency( Note::B, -1 );
		const double noteHz_4th = WellTemperament::GetFrequency( Note::A, 1 );
		const double noteHz_5th = WellTemperament::GetFrequency( Note::D, 2 );
		const double noteHz_6th = WellTemperament::GetFrequency( Note::A, 2 );

		const double noteHz_1st_ = WellTemperament::GetFrequency( Note::A, -2 ) + swell;
		const double noteHz_2nd_ = WellTemperament::GetFrequency( Note::E, -1 ) + ( 3.0 / 2.0 ) * swell;
		const double noteHz_3rd_ = WellTemperament::GetFrequency( Note::B, -1 ) + ( 9.0 / 4.0 ) * swell;
		const double noteHz_4th_ = WellTemperament::GetFrequency( Note::A, 1 ) + 8.0 * swell;
		const double noteHz_5th_ = WellTemperament::GetFrequency( Note::D, 2 ) + 9.0 * swell;
		const double noteHz_6th_ = WellTemperament::GetFrequency( Note::A, 2 ) + 12.0 * swell;

		const SoundElement32* element_1st = SoundGenerator::Generate( noteHz_1st, length, maxDynamics ); 
		const SoundElement32* element_2nd = SoundGenerator::Generate( noteHz_2nd, length, maxDynamics ); 
		const SoundElement32* element_3rd = SoundGenerator::Generate( noteHz_3rd, length, maxDynamics ); 
		const SoundElement32* element_4th = SoundGenerator::Generate( noteHz_4th, length, maxDynamics ); 
		const SoundElement32* element_5th = SoundGenerator::Generate( noteHz_5th, length, maxDynamics ); 
		const SoundElement32* element_6th = SoundGenerator::Generate( noteHz_6th, length, maxDynamics ); 

		const SoundElement32* element_1st_ = SoundGenerator::Generate( noteHz_1st_, length, maxDynamics ); 
		const SoundElement32* element_2nd_ = SoundGenerator::Generate( noteHz_2nd_, length, maxDynamics ); 
		const SoundElement32* element_3rd_ = SoundGenerator::Generate( noteHz_3rd_, length, maxDynamics ); 
		const SoundElement32* element_4th_ = SoundGenerator::Generate( noteHz_4th_, length, maxDynamics ); 
		const SoundElement32* element_5th_ = SoundGenerator::Generate( noteHz_5th_, length, maxDynamics ); 
		const SoundElement32* element_6th_ = SoundGenerator::Generate( noteHz_6th_, length, maxDynamics ); 

		recorder.Record( 0, 0, time, element_1st, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th, 0.5, 0.5 );

		recorder.Record( 0, 0, time, element_1st_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_2nd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_3rd_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_4th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_5th_, 0.5, 0.5 );
		recorder.Record( 0, 0, time, element_6th_, 0.5, 0.5 );
	}
	
	recorder.OutputAudioFile( folderPath + "series_of_chord.wav" );

}
